/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 10:14:50
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-07-12 09:22:56
 */
import { getAreaObj, uploadType } from '@/utils/util'
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '补贴类型', prop: 'subsidyTypeLabel' },
		{ label: '标题', prop: 'policyTitle' },
		{ label: '发文字号', prop: 'policyArticleCode' },
		{ label: '发布日期', prop: 'publishDate' },
		{ label: '关键词', prop: 'policyKeywords' },
		{
			label: '来源层级',
			prop: 'fromLevelLabel',
		},
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

// 新增编辑
export const BaseFormConfig = (detail) => {
	return {
		inline: false,
		showBtn: false,
		labelPosition: 'top',
		column: [
			{
				custome: 'HtmlLabel',
				prop: 'policyTitle',
				flag: 'bgTitle',
				labelPosition: 'top',
				display: detail,
				span: 24,
			},
			{
				label: '标题',
				prop: 'policyTitle',
				type: 'input',
				span: 12,
				rules: [{ required: true, message: '请输入标题' }],
			},
			{
				label: '发文字号',
				prop: 'policyArticleCode',
				type: 'input',
				span: 12,
				rules: [{ required: true, message: '请输入发文字号' }],
			},
			{
				label: '发布日期',
				prop: 'publishDate',
				type: 'date',
				format: 'YYYY年MM月DD日',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
			},
			{
				label: '层级',
				prop: 'policyLevel',
				propName: 'policyLevelLabel',
				type: 'remoteSelect',
				code: 'POLICY_LEVEL',
				api: 'getDictItemList',
				filterKey: 'label',
				multiple: false,
				span: 12,
				rules: [{ required: true, message: '请选择层级' }],
			},
			{
				label: '关键词',
				prop: detail ? 'policyKeywords' : 'policyKeyword',
				filterable: true,
				allowCreate: true,
				multiple: true,
				type: 'select',
				placeholder: '请输入关键词',
				span: 12,
			},
			{
				label: '养老业务标签',
				prop: 'policyTags',
				propName: 'policyTagsLabels',
				type: 'remoteSelect',
				code: 'POLICY_TAGS',
				api: 'getDictItemList',
				filterKey: 'label',
				multiple: true,
				span: 12,
			},
			{
				label: '来源单位',
				prop: 'fromName',
				maxlength: '100',
				type: 'input',
				span: 8,
				rules: [{ required: true, message: '请输入来源单位名称' }],
			},
			{
				label: '来源单位区划',
				prop: 'areas',
				propName: 'areasName',
				regionGrade: 3,
				checkStrictly: true,
				type: 'AplidAreaSelect',
				rules: [{ required: true, message: '请选择来源单位区划' }],
				span: 8,
			},
			{
				label: '来源层级',
				prop: 'fromLevel',
				propName: 'fromLevelLabel',
				type: 'remoteSelect',
				code: 'POLICY_LEVEL',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
				rules: [{ required: true, message: '请选择来源层级' }],
			},

			{
				label: '老人类别',
				prop: 'oldmanType',
				propName: 'oldmanTypeLabel',
				type: 'remoteSelect',
				code: 'ELDERLY_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{
				label: '适应老人年龄',
				prop: 'ageRange',
				type: 'RangeValue',
				span: 8,
			},
			{
				label: '补贴类型',
				prop: 'subsidyType',
				propName: 'subsidyTypeLabel',
				type: 'remoteSelect',
				code: 'SUBSIDY_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
				rules: [{ required: true, message: '请选择补贴类型' }],
			},

			{
				label: '政策内容',
				prop: 'policyContent',
				showWordLimit: true,
				type: 'ueditor',
				height: '20rem',
				rules: [{ required: true, message: '请输入政策内容' }],
				span: 24,
			},
			{
				label: '附件信息',
				prop: 'policyAttachment',
				type: 'upload',
				fileType: uploadType.fileMetaType,
				listType: 'text',
				showFileList: true,
				limit: 4,
				multiple: true,
				custome: 'file',
				span: 24,
			},
		],
	}
}

export const api = {
	index: 'view_dpPolicyDocument_page',
	export: 'dpPolicyDocument_export',
	delete: 'view_dpPolicyDocument_del',
	add: 'view_dpPolicyDocument_add',
	edit: 'view_dpPolicyDocument_edit',
	detail: 'view_dpPolicyDocument_view',
}
export const baseConfig = {
	pageName: '补贴政策文件管理',
	// 数据字典
	dictcodes: ['POLICY_LEVEL', 'POLICY_TAGS', 'ELDERLY_TYPE', 'SUBSIDY_TYPE'],
	rowKey: 'id',
	addLabel: '新增',
	// 删除插入
	tipLabel: 'policyTitle',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
		// 批量搜索
		mulitSet: 'mulitSet',
	},
	paramsObj: {
		code: 3011,
		module: 2,
	},
	// 当前行操作按钮
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: 'view_dpPolicyDocument_page',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: 'view_dpPolicyDocument_edit',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: 'view_dpPolicyDocument_del',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '85%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{
				label: '标题',
				prop: 'policyTitle',
				type: 'input',
				span: 8,
			},
			{
				label: '发文字号',
				prop: 'policyArticleCode',
				type: 'input',
				span: 8,
			},
			{
				label: '来源层级',
				prop: 'fromLevel',
				propName: 'fromLevelLabel',
				type: 'remoteSelect',
				code: 'POLICY_LEVEL',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				span: 8,
			},
			{
				label: '关键词',
				prop: 'policyKeywords',
				type: 'input',
				span: 8,
			},
			{
				label: '发布日期',
				prop: 'publishDateBetween',
				type: 'dateBetween',
				format: 'YYYY年MM月DD',
				valueFormat: 'YYYY-MM-DD HH:mm:ss',
				span: 8,
			},
		],
	},
	// 新增
	formConfig: {
		...BaseFormConfig(false),
		showBtn: true,
	},
	// 列表
	tableConfig,
	// 详情
	detailConfig: BaseFormConfig(true),
	operateFormate: async (row, type) => {
		const areasInfo: any = getAreaObj(row, 'from', 'set')
		return Promise.resolve({
			...row,
			policyKeyword: row.policyKeywords ? row.policyKeywords?.split(',') : [],
			areas: areasInfo.areaIds,
			areasName: areasInfo.names,
		})
	},
	// 新增处理
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, 'from')
			const areasNameObj: any = getAreaObj(form.areasName, 'from')
			const params = {
				...form,
				...areasObj,
				...areasNameObj,
				policyKeywords: form.policyKeyword?.join(','),
				areas: undefined,
				areasName: undefined,
				policyKeyword: undefined,
				code: 1001,
			}
			resolve(params)
		})
	},
}
